<!-- Page header -->
<div class="container">
  <div>查看抑郁问卷测评分数：</div>
  <hr>
  <table border="1px" id="tab1" class="data" >
    <thead>
      <tr>
        <th>序号&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</th>
        <th>测试时间&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</th>
        <th>总分&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</th>
        <th>总均分&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</th>
        <th>阳性回答数&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</th>
        <th>躯体化&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</th>
        <th>强迫症状&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</th>
        <th>人际关系敏感&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</th>
        <th>抑郁&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</th>
        <th>焦虑&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</th>
        <th>敌对&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</th>
        <th>恐怖&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</th>
        <th>偏执&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</th>
        <th>精神病&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</th>
        <th>其他&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</th>
      </tr>
    </thead>
    <tbody id = "tb"></tbody>
  </table>
</div>
  <canvas id="myChart1" width="600" height="130"></canvas>


  <div class="container"  id="sas_div">
    <div>查看焦虑问卷测评分数：</div>
    <hr>
    <table border="1px" id="tab2" class="data">
      <thead>
        <tr>
          <th>序号&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&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&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</th>
        </tr>
      </thead>
      <tbody id = "tb2"></tbody>
    </table>
  </div>
  <canvas id="myChart2" width="600" height="130"></canvas>

<div class="container"  id="sleep_div">
  <div>查看睡眠问卷测评分数：</div>
  <hr>
  <table border="1px" id="tab3" class="data">
    <thead>
      <tr>
        <th>序号&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</th>
        <th>测试时间&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</th>
        <th>PSQI总分&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</th>
        <th>睡眠质量&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</th>
        <th>入睡时间&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</th>
        <th>睡眠时间&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</th>
        <th>睡眠效率&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</th>
        <th>睡眠障碍&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</th>
        <th>催眠药物&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</th>
        <th>日间功能障碍&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</th>
        <th>结果&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</th>
      </tr>
    </thead>
    <tbody id = "tb3"></tbody>
  </table>
</div>
<canvas id="myChart3" width="600" height="130"></canvas>

<hr>
<div style="text-align:center;" ><input type="button" value="确认"  id="cmdSub1"></div>




<!-- Page body -->

<script>
  $(function() {


//========================= 查询用户scl测评记录 =======================
let postData = {
  id : currentStuUser.stuUser.id
}
console.log("----查看预约用户id");
$.ajax({
    type : 'get',
    url : 'scl90/selectAllCon',
  data : postData,
    success : function(respDate) {
      
      //判断状态码
      if(respDate.code == 0) {
       //构造页面
   buidHistoryHtml(respDate.data);
   getValue(respDate.data);

      }else {
        $.toast({
          heading: '警告',
          text: respDate.message,
          icon: 'warning' 
        });
      }
    },
    error : function() {
      $.toast({
        heading: '错误',
        text: '服务器错误，请联系管理员',
        icon: 'error' 
      });
    }

  });

function buidHistoryHtml(data) {
  let table = document.getElementById("tab1");
  let newRow = table.insertRow();

  let tbody = document.getElementById('tb');

  

  
  for(let i = 0; i < data.length; i++) {

    var trow = getDataRow(data[i]);
    tbody.appendChild(trow);
  }
}

function getDataRow(h){  
   var row = document.createElement('tr'); //创建行  
     
   var cellId = document.createElement('td'); //创建第一列id  
   cellId.innerHTML = h.id; //填充数据  
   row.appendChild(cellId); //加入行  ，下面类似  
     
   var cellCreateState = document.createElement('td');//创建第二列name  
   cellCreateState.innerHTML = h.createState;  
   row.appendChild(cellCreateState);  
     
   var cellScore = document.createElement('td');//创建第三列job  
   cellScore.innerHTML = h.score;  
   row.appendChild(cellScore);  

 
 var cellToTalAverage = document.createElement('td');//创建第三列job  
   cellToTalAverage.innerHTML = h.totalAverage;  
   row.appendChild(cellToTalAverage);  

 var cellPositive_Num = document.createElement('td');//创建第三列job  
   cellPositive_Num.innerHTML = h.positive_Num;  
   row.appendChild(cellPositive_Num);  

 var cellSomatization = document.createElement('td');//创建第三列job  
   cellSomatization.innerHTML = h.somatization;  
   row.appendChild(cellSomatization);  

 var cellForced = document.createElement('td');//创建第三列job  
   cellForced.innerHTML = h.forced;  
   row.appendChild(cellForced);  

 var cellRelationship = document.createElement('td');//创建第三列job  
   cellRelationship.innerHTML = h.relationship;  
   row.appendChild(cellRelationship);  

 var cellDepression = document.createElement('td');//创建第三列job  
   cellDepression.innerHTML = h.depression;  
   row.appendChild(cellDepression);  

 var cellAnxiety = document.createElement('td');//创建第三列job  
   cellAnxiety.innerHTML = h.anxiety;  
   row.appendChild(cellAnxiety);  

 var cellHostile = document.createElement('td');//创建第三列job  
   cellHostile.innerHTML = h.hostile;  
   row.appendChild(cellHostile);  

 var cellTerror = document.createElement('td');//创建第三列job  
   cellTerror.innerHTML = h.terror;  
   row.appendChild(cellTerror);  

 var cellBigotry = document.createElement('td');//创建第三列job  
   cellBigotry.innerHTML = h.bigotry;  
   row.appendChild(cellBigotry);  

 var cellMentally = document.createElement('td');//创建第三列job  
   cellMentally.innerHTML = h.mentally;  
   row.appendChild(cellMentally);  

 var cellOther = document.createElement('td');//创建第三列job  
   cellOther.innerHTML = h.other;  
   row.appendChild(cellOther); 
 return row; //返回tr数据      
}      

function getValue(postData) {
const ctx = document.getElementById('myChart1');
const labels = [];
const somatization = [];
const forced = [];
const relationship = [];
const depression = [];
const anxiety = [];
const hostile = [];
const terror = [];
const bigotry = [];
const mentally = [];
const other = [];

for(let i = 0; i < postData.length; i++) {
  labels[i] = postData[i].createState;
  somatization[i] = postData[i].somatization;
  forced[i] = postData[i].forced;
  relationship[i] = postData[i].relationship;
  depression[i] = postData[i].depression;
  anxiety[i] = postData[i].anxiety;
  hostile[i] = postData[i].hostile;
  terror[i] = postData[i].terror;
  bigotry[i] = postData[i].bigotry;
  mentally[i] = postData[i].mentally;
  other[i] = postData[i].other;
}

console.log("查看数据结构集");
console.log(labels);
console.log(somatization);
console.log(forced);
console.log(relationship);
console.log(depression);
console.log(anxiety);
console.log(hostile);
console.log(terror);
console.log(bigotry);
console.log(mentally);
console.log(other);

if(postData.length == 0) {
  console.log("没有测评数据！");
  return 0;
} else {
  console.log("有一条以上的数据！");
  const data = {
    labels: labels,
    datasets: [
      {
      label: '躯体化',
      data: somatization,
              fill: false,
              borderColor: 'rgb(75, 192, 192)', // 设置线的颜色
              tension: 0.1
       },
       {
      label: '强迫症状',
      data: forced,
              fill: false,
              borderColor: 'rgb(255, 51, 100)', // 设置线的颜色
              tension: 0.1
       },
       {
      label: '人际关系敏感',
      data: relationship,
              fill: false,
              borderColor: 'rgb(255, 51, 190)', // 设置线的颜色
              tension: 0.1
       },
       {
      label: '抑郁',
      data: depression,
              fill: false,
              borderColor: 'rgb(175, 51, 255)', // 设置线的颜色
              tension: 0.1
       },
       {
      label: '焦虑',
      data: anxiety,
              fill: false,
              borderColor: 'rgb(51, 255, 141)', // 设置线的颜色
              tension: 0.1
       },
       {
      label: '敌对',
      data: hostile,
              fill: false,
              borderColor: 'rgb(184, 255, 51)', // 设置线的颜色
              tension: 0.1
       },
       {
      label: '恐怖',
      data: terror,
              fill: false,
              borderColor: 'rgb(255, 193, 51)', // 设置线的颜色
              tension: 0.1
       },
       {
      label: '偏执',
      data: bigotry,
              fill: false,
              borderColor: 'rgb(29, 27, 22)', // 设置线的颜色
              tension: 0.1
       },
       {
      label: '精神病',
      data: mentally,
              fill: false,
              borderColor: 'rgb(141, 138, 132)', // 设置线的颜色
              tension: 0.1
       },
       {
      label: '其他',
      data: other,
              fill: false,
              borderColor: 'rgb(133, 96, 11)', // 设置线的颜色
              tension: 0.1
       }
    ]
  };
  const config = {
    type: 'line', // 设置图表类型
    data: data,
  };
  console.log("-------------------");
  const myChart = new Chart(ctx, config);
}
}


//========================= 查询用户sas测评记录 =======================
function sas(){


$.ajax({
    type : 'get',
    url : 'sas/selectAllCon',
  data : postData,
    success : function(respDate) {
      
      //判断状态码
      if(respDate.code == 0) {
       //构造页面
   buidHistoryHtml(respDate.data);
   getValue(respDate.data);

      }else {
        $.toast({
          heading: '警告',
          text: respDate.message,
          icon: 'warning' 
        });
      }
    },
    error : function() {
      $.toast({
        heading: '错误',
        text: '服务器错误，请联系管理员',
        icon: 'error' 
      });
    }

  });

function buidHistoryHtml(data) {
  let table = document.getElementById("tab2");
  let newRow = table.insertRow();

  let tbody = document.getElementById('tb2');

  

  
  for(let i = 0; i < data.length; i++) {

    var trow = getDataRow(data[i]);
    tbody.appendChild(trow);
  }
}

function getDataRow(h){  
   var row = document.createElement('tr'); //创建行  
     
   var cellId = document.createElement('td'); //创建第一列id  
   cellId.innerHTML = h.id; //填充数据  
   row.appendChild(cellId); //加入行  ，下面类似  
     
   var cellCreateState = document.createElement('td');//创建第二列name  
   cellCreateState.innerHTML = h.createState;  
   row.appendChild(cellCreateState);  
     
   var cell_Anxiety_Score = document.createElement('td');//创建第三列job  
   cell_Anxiety_Score.innerHTML = h.anxiety_Score;  
   row.appendChild(cell_Anxiety_Score);  

 var cellResult= document.createElement('td');//创建第三列job  
 let num = h.anxiety_Score;
 if(num < 50) {
  cellResult.innerHTML = "无明显焦虑";
 }else if (num >=50 && num < 60) {
  cellResult.innerHTML = "轻度焦虑";
 }else if (num >=60 && num < 70) {
  cellResult.innerHTML = "中度焦虑";
 } else {
  cellResult.innerHTML = "重度焦虑";
 }
 row.appendChild(cellResult);  
 
 return row; //返回tr数据      
}

function getValue(postData) {
const ctx = document.getElementById('myChart2');
const labels = [];
const data1 = [];

for(let i = 0; i < postData.length; i++) {
  labels[i] = postData[i].createState;
  data1[i] = postData[i].anxiety_Score;
}

console.log("查看数据结构集");
console.log(labels);
console.log(data1);

if(postData.length == 0) {
  console.log("没有测评数据！");
  
  return 0;
} else {
  console.log("有一条以上的数据！");
  const data = {
    labels: labels,
    datasets: [{
      label: '焦虑值',
      data: data1,
              fill: false,
              borderColor: 'rgb(75, 192, 192)', // 设置线的颜色
              tension: 0.1
    }]
  };
  const config = {
    type: 'line', // 设置图表类型
    data: data,
  };
  console.log("-------------------");
  const myChart = new Chart(ctx, config);
}
}
}
sas();

//========================= 查询用户sleep测评记录 =======================
function sleep() {

$.ajax({
    type : 'get',
    url : 'sleep/selectAllCon',
  data : postData,
    success : function(respDate) {
      
      //判断状态码
      if(respDate.code == 0) {
       //构造页面
   buidHistoryHtml(respDate.data);
   getValue(respDate.data);
      }else {
        $.toast({
          heading: '警告',
          text: respDate.message,
          icon: 'warning' 
        });
      }
    },
    error : function() {
      $.toast({
        heading: '错误',
        text: '服务器错误，请联系管理员',
        icon: 'error' 
      });
    }

  });

function buidHistoryHtml(data) {
  let table = document.getElementById("tab3");
  let newRow = table.insertRow();

  let tbody = document.getElementById('tb3');

  

  
  for(let i = 0; i < data.length; i++) {

    var trow = getDataRow(data[i]);
    tbody.appendChild(trow);
  }
}

function getDataRow(h){  
   var row = document.createElement('tr'); //创建行  
     
   var cellId = document.createElement('td'); //创建第一列id  
   cellId.innerHTML = h.id; //填充数据  
   row.appendChild(cellId); //加入行  ，下面类似  
     
   var cellCreateState = document.createElement('td');//创建第二列name  
   cellCreateState.innerHTML = h.createState;  
   row.appendChild(cellCreateState);  

 var cellScore = document.createElement('td');//创建第三列job  
   cellScore.innerHTML = h.score;  
   row.appendChild(cellScore);  

 var cellQuality = document.createElement('td');//创建第三列job  
   cellQuality.innerHTML = h.quality;  
   row.appendChild(cellQuality);  
     
  
 var cellAsleep = document.createElement('td');//创建第三列job  
   cellAsleep.innerHTML = h.asleep;  
   row.appendChild(cellAsleep);  

 var cellSleepTime = document.createElement('td');//创建第三列job  
   cellSleepTime.innerHTML = h.sleepTime;  
   row.appendChild(cellSleepTime);  

 var cellSleepEfficiency = document.createElement('td');//创建第三列job  
   cellSleepEfficiency.innerHTML = h.sleepEfficiency;  
   row.appendChild(cellSleepEfficiency);  

 var cellSleepDisturbances = document.createElement('td');//创建第三列job  
   cellSleepDisturbances.innerHTML = h.sleepDisturbances;  
   row.appendChild(cellSleepDisturbances);  

 var cellHypnoticDrugs = document.createElement('td');//创建第三列job  
   cellHypnoticDrugs.innerHTML = h.hypnoticDrugs;  
   row.appendChild(cellHypnoticDrugs);  

 var cellDysfunction = document.createElement('td');//创建第三列job  
   cellDysfunction.innerHTML = h.dysfunction;  
   row.appendChild(cellDysfunction);  

 var cellResult= document.createElement('td');//创建第三列job  

 let num = h.score;
 if(num >=0 && num < 6) {
  cellResult.innerHTML = "睡眠质量很好";
 } else if (num >=6 && num < 11) {
  cellResult.innerHTML = "睡眠质量较好";
 }else if (num >=11 && num < 16) {
  cellResult.innerHTML = "睡眠质量一般";
 }else {
  cellResult.innerHTML = "睡眠质量很差";
 }
   row.appendChild(cellResult);  


 return row; //返回tr数据      
}      

function getValue(postData) {
const ctx = document.getElementById('myChart3');
const labels = [];
const quality = [];
const asleep = [];
const sleepTime = [];
const sleepEfficiency = [];
const sleepDisturbances = [];
const hypnoticDrugs = [];
const dysfunction = [];


for(let i = 0; i < postData.length; i++) {
  labels[i] = postData[i].createState;
  quality[i] = postData[i].quality;
  asleep[i] = postData[i].asleep;
  sleepTime[i] = postData[i].sleepTime;
  sleepEfficiency[i] = postData[i].sleepEfficiency;
  sleepDisturbances[i] = postData[i].sleepDisturbances;
  hypnoticDrugs[i] = postData[i].hypnoticDrugs;
  dysfunction[i] = postData[i].dysfunction;
}

console.log("查看数据结构集");
console.log(labels);
console.log(quality);
console.log(asleep);
console.log(sleepTime);
console.log(sleepEfficiency);
console.log(sleepDisturbances);
console.log(hypnoticDrugs);
console.log(dysfunction);

if(postData.length == 0) {
  console.log("没有测评数据！");
  
  return 0;
} else {
  console.log("有一条以上的数据！");
  const data = {
    labels: labels,
    datasets: [
      {
      label: '睡眠质量',
      data: quality,
              fill: false,
              borderColor: 'rgb(75, 192, 192)', // 设置线的颜色
              tension: 0.1
       },
       {
      label: '入睡时间',
      data: asleep,
              fill: false,
              borderColor: 'rgb(255, 51, 100)', // 设置线的颜色
              tension: 0.1
       },
       {
      label: '睡眠时间',
      data: sleepTime,
              fill: false,
              borderColor: 'rgb(255, 51, 190)', // 设置线的颜色
              tension: 0.1
       },
       {
      label: '睡眠效率',
      data: sleepEfficiency,
              fill: false,
              borderColor: 'rgb(175, 51, 255)', // 设置线的颜色
              tension: 0.1
       },
       {
      label: '睡眠障碍',
      data: sleepDisturbances,
              fill: false,
              borderColor: 'rgb(51, 255, 141)', // 设置线的颜色
              tension: 0.1
       },
       {
      label: '催眠药物',
      data: hypnoticDrugs,
              fill: false,
              borderColor: 'rgb(184, 255, 51)', // 设置线的颜色
              tension: 0.1
       },
       {
      label: '日间功能障碍',
      data: dysfunction,
              fill: false,
              borderColor: 'rgb(255, 193, 51)', // 设置线的颜色
              tension: 0.1
       }
    ]
  };
  const config = {
    type: 'line', // 设置图表类型
    data: data,
  };
  console.log("-------------------");
  const myChart = new Chart(ctx, config);
}
}
}
sleep();

let IsNoBokingId = {
  id : currentStuUser.id
}
console.log('--------查看未预约的id');
console.log(currentStuUser.id);
$('#cmdSub1').click(function() {

  $.ajax({

    type : 'get',
    url : 'booking/updateState',
    data : IsNoBokingId,
    success : function(respDate) {
      //判断状态码
      if(respDate.code == 0) {
       //构造页面
       $.toast({
          heading: '成功',
          text: respDate.message,
          icon: 'success' 
        });
        changeNavActive($('#nav_board_index'));
      }else {
        $.toast({
          heading: '警告',
          text: respDate.message,
          icon: 'warning' 
        });
      }
    },
    error : function() {
      $.toast({
        heading: '错误',
        text: '服务器错误，请联系管理员',
        icon: 'error' 
      });
    }


  }) 

});
});
  
</script>